<template>
  <div class="app-container">
    <el-form size="small" :inline="true" v-show="showSearch">
      <el-form-item label="性别">
        <el-select v-model="sexstatus" placeholder="请选择性别">
          <el-option
            v-for="item in sexoptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备">
        <el-select v-model="devicestatus" placeholder="请选择有无绑定设备">
          <el-option
            v-for="item in deviceoptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="关键字">
        <!--  @keyup.enter.native="handleQuery" -->
        <el-input placeholder="请输入使用者名称" />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="使用者姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="生日" align="center" prop="birthday" />
      <el-table-column label="身高" align="center" prop="height" />
      <el-table-column label="体重" align="center" prop="weight" />
      <el-table-column label="所属机构" align="center" prop="agency" />
      <el-table-column label="房间号" align="center" prop="room" />
      <el-table-column label="床号" align="center" prop="bed" />
      <el-table-column label="设备ID" align="center" prop="deviceid" />
      <el-table-column label="入住日期" align="center" prop="checkindate" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination :total="total" />

    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="800px">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="70px"
        label-position="left"
      >
        <div class="form-row">
          <div style="display: flex; align-items: center">
            <el-upload
              class="avatar-uploader"
              action=""
              :show-file-list="false"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar" />
              <i v-else class="el-icon-picture avatar-uploader-icon"></i>
            </el-upload>
            <div style="font-size: 12px; color: #c0c4cc; margin-left: 5px">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </div>
          <el-form-item label="姓名" prop="userName">
            <el-input v-model="form.username" placeholder="请输入姓名" />
          </el-form-item>
        </div>
        <div class="form-row">
          <el-form-item label="性别" prop="sex">
            <el-radio-group v-model="form.sex">
              <el-radio :label="0">男</el-radio>
              <el-radio :label="1">女</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="出生日期" prop="birthday">
            <el-date-picker
              v-model="form.birthday"
              type="date"
              placeholder="请选择出生日期"
            >
            </el-date-picker>
          </el-form-item>
        </div>
        <div class="form-row">
          <el-form-item label="血型" prop="bloodtype">
            <el-select v-model="form.bloodtype" placeholder="请选择血型">
              <el-option
                v-for="item in bloodtypeoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="优先级" prop="priority">
            <el-select v-model="form.priority" placeholder="请选择优先级">
              <el-option
                v-for="item in priorityoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="form-row">
          <el-form-item label="体重" prop="weight">
            <el-input v-model="form.weight" placeholder="请输入体重" />
          </el-form-item>
          <el-form-item label="身高" prop="height">
            <el-input v-model="form.height" placeholder="请输入身高" />
          </el-form-item>
        </div>
        <div class="form-row agency-row">
          <el-form-item label="所属机构" prop="agency">
            <el-select v-model="form.agency" placeholder="请选择所属机构">
            </el-select>
          </el-form-item>
          <el-form-item label="房间号" prop="room">
            <el-select v-model="form.room" placeholder="请选择房间号">
              <el-option
                v-for="item in agencyoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="床号" prop="bed">
            <el-select v-model="form.bed" placeholder="请选择床号">
              <el-option
                v-for="item in bedoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="form-row">
          <el-form-item label="入住日期" prop="checkindate">
            <el-date-picker
              v-model="form.checkindate"
              type="date"
              placeholder="请选择入住日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="手机号" prop="phonenumber">
            <el-input v-model="form.phonenumber" placeholder="请输入手机号" />
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 100,
      // 岗位表格数据
      postList: [
        {
          name: "上松和子",
          sex: "女",
          birthday: "1932-05-24",
          height: 155,
          weight: 30,
          agency: "希望の轍＿長久保",
          room: "8号室",
          bed: "- / 28181000050098",
          deviceid: "SC60001884",
          checkindate: "2024-07-03 00:00:00",
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      devicestatus: null,
      //搜索栏设备状态
      deviceoptions: [
        {
          value: 2,
          label: "全部",
        },
        {
          value: 1,
          label: "有",
        },
        {
          value: 0,
          label: "无",
        },
      ],
      //搜索栏性别
      sexstatus: null,
      sexoptions: [
        {
          value: 2,
          label: "全部",
        },
        {
          value: 0,
          label: "男",
        },
        {
          value: 1,
          label: "女",
        },
      ],
      // 表单血型
      bloodtypeoptions: [
        {
          value: "A",
          label: "A",
        },
        {
          value: "B",
          label: "B",
        },
        {
          value: "AB",
          label: "AB",
        },
        {
          value: "O",
          label: "O",
        },
      ],
      //表单优先级
      priorityoptions: [
        {
          value: 1,
          label: "1",
        },
        {
          value: 2,
          label: "2",
        },
        {
          value: 3,
          label: "3",
        },
      ],
      //表单机构
      agencyoptions: [],
      //表单房间
      roomoptions: [],
      //表单床号
      bedoptions: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        postName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" },
        ],
        postCode: [
          { required: true, message: "岗位编码不能为空", trigger: "blur" },
        ],
        postSort: [
          { required: true, message: "岗位顺序不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {},
  methods: {
    //取消按钮
    cancel() {
      // this.open = false;
      // this.reset();
    },
    //表单重置
    reset() {
      this.form = {
        username: undefined,
        sex: undefined,
        birthday: undefined,
        bloodtype: "",
        weight: undefined,
        height: undefined,
        phonenumber: undefined,
        priority: 1,
        province: "",
        city: "",
        county: "",
        detailadress: "",
        agency: "",
        room: "",
        bed: "",
        checkindate: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageNum = 1;
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      // this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      // this.ids = selection.map(item => item.postId)
      // this.single = selection.length!=1
      // this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      this.open = true;
      this.title = "添加使用者";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const postId = row.postId || this.ids
      // getPost(postId).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改岗位";
      // });
    },
    /** 提交按钮 */
    submitForm: function () {
      // this.$refs["form"].validate(valid => {
      //   if (valid) {
      //     if (this.form.postId != undefined) {
      //       updatePost(this.form).then(response => {
      //         this.$modal.msgSuccess("修改成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     } else {
      //       addPost(this.form).then(response => {
      //         this.$modal.msgSuccess("新增成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     }
      //   }
      // });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // const postIds = row.postId || this.ids;
       this.$modal.confirm('是否确认删除数据项？').then(function() {
      //   return delPost(postIds);
       }).then(() => {
      //   //this.getList();
         this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // this.download('system/post/export', {
      //   ...this.queryParams
      // }, `post_${new Date().getTime()}.xlsx`)
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 40px;
}
.el-dialog__body {
  .el-form {
    padding-left: 30px;
    .form-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 60px;
      .el-form-item {
        width: 320px;
        margin-right: 20px;
        margin-bottom: 0;
        .el-input,
        .el-select {
          width: 220px;
        }
      }
    }
    .agency-row {
      .el-select {
        width: 160px !important;
      }
    }
  }
}
</style>
<style lang="scss">
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 60px;
  height: 60px;
  line-height: 60px;
  text-align: center;
}
.avatar {
  width: 60px;
  height: 60px;
  display: block;
}
</style>
